package com.example.wechatlistview.fragments;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.wechatlistview.R;
import com.example.wechatlistview.resmanager.itemType;
import com.example.wechatlistview.resmanager.DataSource;
import com.example.wechatlistview.events.controllers.ClickController;
import com.example.wechatlistview.tools.DividerDecoration;
import com.example.wechatlistview.tools.SectionCreater;

import io.github.luizgrp.sectionedrecyclerviewadapter.SectionedRecyclerViewAdapter;

public class fg_discover extends Fragment {

    private Context context;
    RecyclerView recyclerView;
    private final int[] cutIndex = {1, 2, 4, 6, 7, 8, 9};
    /**
     * 键数组
     * 头像组
     * 名称组
     * 标签组
     */
    private String[] keyAry;
    private Object[] headAry;
    private String[] nameAry;
    private String[] tagAry;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_discover, container, false);
        recyclerView = (RecyclerView) v.findViewById(R.id.discover_list);
        headAry = new Object[]{
                R.mipmap.heads_discover_moment, R.mipmap.heads_discover_channel, R.mipmap.heads_discover_scan,
                R.mipmap.heads_discover_shake, R.mipmap.heads_discover_social, R.mipmap.heads_discover_search,
                R.mipmap.heads_discover_stream, R.mipmap.heads_discover_game, R.mipmap.heads_discover_minipro
        };

        return v;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        context = getActivity();
        /**
         * 初始化键值
         */
        DataSource ds = new DataSource(context);
        keyAry = ds.GetStrArrayFromRes(R.array.key_discover);
        nameAry = ds.GetStrArrayFromRes(R.array.discover_name);
        tagAry = ds.GetStrArrayFromRes(R.array.tag_discover);

        SectionedRecyclerViewAdapter sectionedAdapter = SectionCreater.create(itemType.holderType.discover, keyAry, new Object[][]{headAry, nameAry, tagAry}, cutIndex, new ClickController.HolderBuilder(context));

        DividerDecoration decoration = new DividerDecoration(context);
        decoration.setDrawable(ds.GetDrawableFromRes(R.drawable.btn_contacts));


        recyclerView.addItemDecoration(decoration);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(sectionedAdapter);

    }


}
